// 样式混入

// 清除浮动
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

// 文本溢出省略号
@mixin text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// 多行文本溢出省略号
@mixin text-ellipsis-multi($lines: 2) {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: $lines;
  overflow: hidden;
  text-overflow: ellipsis;
}

// 居中定位
@mixin center-absolute {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 垂直居中
@mixin center-vertical {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

// 水平居中
@mixin center-horizontal {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

// Flex布局居中
@mixin flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

// Flex布局垂直居中
@mixin flex-center-vertical {
  display: flex;
  align-items: center;
}

// Flex布局水平居中
@mixin flex-center-horizontal {
  display: flex;
  justify-content: center;
}

// Flex布局两端对齐
@mixin flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

// Flex布局均匀分布
@mixin flex-around {
  display: flex;
  align-items: center;
  justify-content: space-around;
}

// 按钮样式
@mixin button-base {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: all 0.3s ease;
  user-select: none;
  
  &:disabled {
    cursor: not-allowed;
    opacity: 0.6;
  }
}

// 主要按钮
@mixin button-primary {
  @include button-base;
  background-color: #007AFF;
  color: white;
  
  &:hover:not(:disabled) {
    background-color: #0056CC;
  }
  
  &:active:not(:disabled) {
    background-color: #004499;
  }
}

// 次要按钮
@mixin button-secondary {
  @include button-base;
  background-color: transparent;
  color: #007AFF;
  border: 1px solid #007AFF;
  
  &:hover:not(:disabled) {
    background-color: #007AFF;
    color: white;
  }
}

// 输入框样式
@mixin input-base {
  width: 100%;
  border: 1px solid #D9D9D9;
  border-radius: 4px;
  padding: 0 12px;
  font-size: 14px;
  line-height: 1.5;
  transition: border-color 0.3s ease;
  
  &:focus {
    outline: none;
    border-color: #007AFF;
  }
  
  &:disabled {
    background-color: #FAFAFA;
    cursor: not-allowed;
  }
  
  &::placeholder {
    color: #8C8C8C;
  }
}

// 卡片样式
@mixin card-base {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  overflow: hidden;
}

// 商品卡片
@mixin product-card {
  @include card-base;
  transition: transform $transition-duration $transition-timing;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: $product-card-shadow;
  }
}

// 列表项样式
@mixin list-item {
  padding: 16px;
  border-bottom: 1px solid #F0F0F0;
  background-color: #fff;
  
  &:last-child {
    border-bottom: none;
  }
}

// 加载动画
@mixin loading-spinner($size: 24px, $color: #007AFF) {
  width: $size;
  height: $size;
  border: 2px solid transparent;
  border-top-color: $color;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

// 渐变背景
@mixin gradient($start-color, $end-color, $direction: to right) {
  background: linear-gradient($direction, $start-color, $end-color);
}

// 阴影效果
@mixin shadow($level: 1) {
  @if $level == 1 {
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
  } @else if $level == 2 {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  } @else if $level == 3 {
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  }
}

// 响应式断点
@mixin mobile {
  @media (max-width: 767px) {
    @content;
  }
}

@mixin tablet {
  @media (min-width: 768px) and (max-width: 1023px) {
    @content;
  }
}

@mixin desktop {
  @media (min-width: 1024px) {
    @content;
  }
}

// 安全区域适配
@mixin safe-area($property: padding-bottom) {
  #{$property}: constant(safe-area-inset-bottom);
  #{$property}: env(safe-area-inset-bottom);
}

// 1px边框（解决移动端边框模糊问题）
@mixin hairline($direction: bottom, $color: $border-color) {
  position: relative;
  
  &::after {
    content: '';
    position: absolute;
    background-color: $color;
    
    @if $direction == top {
      top: 0;
      left: 0;
      right: 0;
      height: 1px;
      transform: scaleY(0.5);
    } @else if $direction == bottom {
      bottom: 0;
      left: 0;
      right: 0;
      height: 1px;
      transform: scaleY(0.5);
    } @else if $direction == left {
      top: 0;
      left: 0;
      bottom: 0;
      width: 1px;
      transform: scaleX(0.5);
    } @else if $direction == right {
      top: 0;
      right: 0;
      bottom: 0;
      width: 1px;
    }
  }
}

// 主要按钮样式
@mixin button-primary {
  background-color: $primary-color;
  color: white;
  border: none;
  border-radius: $border-radius;
  font-size: $font-size-base;
  font-weight: $font-weight-medium;
  
  &:active {
    background-color: darken($primary-color, 10%);
  }
  
  &:disabled {
    background-color: $text-color-disabled;
    color: $text-color-secondary;
  }
}

// 次要按钮样式
@mixin button-secondary {
  background-color: $bg-color-white;
  color: $text-color-primary;
  border: 1px solid $border-color;
  border-radius: $border-radius;
  font-size: $font-size-base;
  
  &:active {
    background-color: $bg-color-light;
  }
}

// 危险按钮样式
@mixin button-danger {
  background-color: $error-color;
  color: white;
  border: none;
  border-radius: $border-radius;
  font-size: $font-size-base;
  font-weight: $font-weight-medium;
  
  &:active {
    background-color: darken($error-color, 10%);
  }
}

// 卡片样式
@mixin card {
  background-color: $bg-color-white;
  border-radius: $border-radius-lg;
  box-shadow: $box-shadow-light;
  overflow: hidden;
}

// 输入框样式
@mixin input-base {
  width: 100%;
  height: $input-height-base;
  padding: 0 $input-padding-horizontal;
  border: 1px solid $border-color;
  border-radius: $border-radius;
  font-size: $font-size-base;
  color: $text-color-primary;
  background-color: $bg-color-white;
  
  &:focus {
    border-color: $primary-color;
    outline: none;
  }
  
  &::placeholder {
    color: $text-color-placeholder;
  }
}

// 标签页样式
@mixin tabs {
  display: flex;
  background-color: $bg-color-white;
  border-bottom: 1px solid $border-color-light;
}

@mixin tab-item {
  flex: 1;
  padding: $spacing-md;
  text-align: center;
  font-size: $font-size-base;
  color: $text-color-secondary;
  border-bottom: 2px solid transparent;
  transition: all $transition-duration;
  
  &.active {
    color: $primary-color;
    border-bottom-color: $primary-color;
  }
}

// 列表项样式
@mixin list-item {
  display: flex;
  align-items: center;
  padding: $list-item-padding;
  background-color: $bg-color-white;
  border-bottom: 1px solid $list-item-border-color;
  
  &:last-child {
    border-bottom: none;
  }
}

// 加载动画
@mixin loading-spinner {
  width: $loading-size;
  height: $loading-size;
  border: 2px solid $border-color-light;
  border-top: 2px solid $loading-color;
  border-radius: $border-radius-circle;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

// 渐变背景
@mixin gradient-primary {
  background: linear-gradient(135deg, $primary-color, lighten($primary-color, 20%));
}

@mixin gradient-success {
  background: linear-gradient(135deg, $success-color, lighten($success-color, 20%));
}

@mixin gradient-warning {
  background: linear-gradient(135deg, $warning-color, lighten($warning-color, 20%));
}

@mixin gradient-error {
  background: linear-gradient(135deg, $error-color, lighten($error-color, 20%));
}

// 阴影效果
@mixin shadow-sm {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

@mixin shadow-md {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

@mixin shadow-lg {
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

// 响应式断点
@mixin respond-to($breakpoint) {
  @if $breakpoint == xs {
    @media (max-width: $breakpoint-xs) { @content; }
  } @else if $breakpoint == sm {
    @media (min-width: $breakpoint-sm) { @content; }
  } @else if $breakpoint == md {
    @media (min-width: $breakpoint-md) { @content; }
  } @else if $breakpoint == lg {
    @media (min-width: $breakpoint-lg) { @content; }
  } @else if $breakpoint == xl {
    @media (min-width: $breakpoint-xl) { @content; }
  }
}

// 清除浮动
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

// 绝对居中
@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 弹性布局居中
@mixin flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

@mixin flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

@mixin flex-start {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

@mixin flex-end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

// 滚动条样式
@mixin scrollbar {
  &::-webkit-scrollbar {
    width: 6px;
  }
  
  &::-webkit-scrollbar-track {
    background: $bg-color-light;
    border-radius: 3px;
  }
  
  &::-webkit-scrollbar-thumb {
    background: $border-color;
    border-radius: 3px;
    
    &:hover {
      background: $text-color-secondary;
    }
  }
}

// 禁用选择
@mixin no-select {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

// 过渡动画
@mixin transition($property: all, $duration: $transition-duration, $timing: $transition-timing) {
  transition: $property $duration $timing;
}

// 变换
@mixin transform($transforms) {
  transform: $transforms;
}

// 边框圆角
@mixin border-radius($radius: $border-radius) {
  border-radius: $radius;
}

// 文本阴影
@mixin text-shadow($x: 0, $y: 1px, $blur: 2px, $color: rgba(0, 0, 0, 0.1)) {
  text-shadow: $x $y $blur $color;
} 